package com.blustreaksw.cyclecoach;

import com.blustreaksw.cyclecoach.data.UserProfile;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

public class UserProfileActivity extends FragmentActivity {

	protected UserProfile mUserProfile;
	private boolean mWizardActivity;
	private boolean mProfileModified;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mUserProfile = UserProfile.getInstance(getApplicationContext());
		mProfileModified = false;
	}
	
	public UserProfile getUserProfile() { return mUserProfile; }
	
	public boolean isWizardActivity() { return mWizardActivity; }
	
	public void setUsedForWizard(boolean value) { mWizardActivity = value; }
	
	public boolean isProfileModified() { return mProfileModified; }
	public void setProfileModified() { mProfileModified = true; }
	public void clearProfileModified() { mProfileModified = false; }
	
	
	public boolean validateFields() {
				
		if(UserProfile.isValidUsername(mUserProfile.getUserName()) == false) {
			Toast.makeText(this, "Please enter a valid username. Upper and lower case\nletters and numbers are allowed.", Toast.LENGTH_SHORT).show();
			return false;
			
		} else if(mUserProfile.verifyUserNameUnique(mUserProfile.getUserName()) == false) {
			Toast.makeText(this, String.format("User name %s is already in use.", mUserProfile.getUserName()), Toast.LENGTH_SHORT).show();
			return false;
			
		} else if(UserProfile.isValidEmail(mUserProfile.getUserEmail()) == false) {
			Toast.makeText(this, "Please enter a valid email address", Toast.LENGTH_SHORT).show();
			return false;
			
		} else if(mUserProfile.isValidHeight(mUserProfile.getHeight()) == false) {
			Toast.makeText(this, "Please enter a valid height.", Toast.LENGTH_SHORT).show();
			return false;
			
		} else if(mUserProfile.isValidWeight(mUserProfile.getWeight()) == false) {
			Toast.makeText(this, "Please enter a valid weight.", Toast.LENGTH_SHORT).show();
			return false;
			
		} else if(mUserProfile.getGender().equals(UserProfile.Gender.UNKNOWN)) {
			Toast.makeText(this, "Please select a gender.", Toast.LENGTH_SHORT).show();
			return false;
		}
		
		return true;
	}
}
